package com.qf.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RegistServlet", urlPatterns = "/registServlet")
public class RegistServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        // 2、获取页面传入的参数
        String name = request.getParameter("name");

        //3、判断以及实现业务
        String result = null;
        if (name.equals("root") || name.equals("admin")){
            //我们定义2代表该用户已经存在
            result = "2";
        }else {
            //定义该用户可以注册
            result = "1";
        }

        //通过响应写数据到页面
        response.getWriter().write(result);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
